<template>
  <div class="page-container">
    <!-- 卡片 -->
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>黑马面经运营后台</span>
      </div>
      <!-- 表单 -->
      <el-form  label-position="top" :model="user" :rules="rules" ref="form">
        <el-form-item label="用户名" prop="username">
          <el-input v-model="user.username"></el-input>
        </el-form-item>

        <el-form-item label="密码" prop="password">
          <el-input type="password" v-model="user.password"></el-input>
        </el-form-item>
        <!-- 按钮 -->
        <el-form-item class="form-operation">
          <el-button type="primary" @click="login">登录</el-button>
          <el-button @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      user: {
        username: '',
        password: '',
      },
      //   表单校验
      rules: {
        username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
      },
    };
  },
  methods: {
    // 登录校验
    async login() {
      await this.$refs.form.validate();
      console.log('表单校验');
      //   action从登录这里拿到token，，token在user对象里面，保存到vuex中
      this.$store.dispatch('user/login', this.user);
    },
    // 表单重置
    reset() {
      this.$refs.form.resetFields();
      console.log('表单重置');
    },
  },
};
</script>
<style scoped>
.page-container{
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;

}
.box-card {
    width: 33%;
    border: 0;
}
::v-deep .el-card__header{
    background-color: #727cf5;
    text-align: center;
    color: #fff;
}
.form-operation{
    color: #fff;
    margin-bottom: 0;
    text-align: center;
}
</style>
